package com.qianxun.module.datasource1.admin.view;

import com.qianxun.framework.common.util.ObjectUtil;
import com.qianxun.module.datasource1.admin.entity.SysMenu;
import com.qianxun.module.datasource1.admin.service.SysMenuService;
import com.qianxun.module.base.view.BaseViewController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author: huwei
 * @date: 2019/11/13 15:05
 * @version: 1.0.0
 */
@Controller
@RequestMapping(value = {"/admin/menu"})
public class SysMenuViewController extends BaseViewController {
    private static final String  VIEW_PAGE_PREFIX = "module/admin/sysMenu";

    @Resource
    private SysMenuService sysMenuService;

    @Override
    protected String prefix() {
        return VIEW_PAGE_PREFIX;
    }


    @Override
    public ModelAndView toAdd(ModelAndView modelAndView, Long id, String key, HttpServletRequest request, HttpServletResponse response) {
        //小功能，显示添加菜单，同级目录的最后排序值
        SysMenu lastMenu = sysMenuService.getOneMaxSortMenuByPid(ObjectUtil.isNull(id) ? 0 : id);
        modelAndView.addObject("nextSort" ,ObjectUtil.isNull(lastMenu) ? 0 : lastMenu.getSort() + 1);
        return super.toAdd(modelAndView, id, key, request, response);
    }
}
